package martin.tpfinal.common.data;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Constantes {

	/*
	 *       

        otros "0.0;0.0;0.0";

	  	puerta -> 	1.0;0.0;1.0	
		radio -> 	0.0;1.0;0.0	
		tv   -> 	0.0;1.0;1.0	
		persiana -> 1.0;1.0;1.0	
		luces -> 	0.0;0.0;1.0	
	 */
	
	public static final String PERSIANA_STRING="persiana";
	public static final double[] PERSIANA_DOUBLE={1.0,1.0,1.0};

	public static final String LUCES_STRING="luces";
	public static final double[] LUCES_DOUBLE={0.0,0.0,1.0};

	public static final String TV_STRING="tv";
	public static final double[] TV_DOUBLE={0.0,1.0,1.0};

	public static final String RADIO_STRING="radio";
	public static final double[] RADIO_DOUBLE={0.0,1.0,0.0};

	public static final String PUERTA_STRING="puerta";
	public static final double[] PUERTA_DOUBLE={1.0,0.0,1.0};
	
	public static final String NO_ENCONTRO="noEncontro";
	public static final double[] NO_ENCONTRO_DOUBLE={-1.0,-1.0,-1.0};
	
	public static final String ERROR_STRING="error";
	public static final double[] ERROR_DOUBLE={-2.0,-2.0,-2.0};
	
	public static Map<String, double[]> palabras = new HashMap<String, double[]>();
	
	static{
			palabras.put(PERSIANA_STRING,PERSIANA_DOUBLE);
			palabras.put(LUCES_STRING,LUCES_DOUBLE);
			palabras.put(TV_STRING,TV_DOUBLE);
			palabras.put(RADIO_STRING,RADIO_DOUBLE);
			palabras.put(PUERTA_STRING,PUERTA_DOUBLE);
			palabras.put(ERROR_STRING,ERROR_DOUBLE);
	}
	
	public Constantes(){
	    
	}
	
	public static String getStringOfDouble(double[] entrada){
		
		boolean encontro=false;
		Iterator<Map.Entry<String,double[]>> itPalabras=palabras.entrySet().iterator();
		
		while (itPalabras.hasNext()){
			Map.Entry<String,double[]> palabraEntry = itPalabras.next();
			
			double[] palabra = palabraEntry.getValue();
			
			for (int j=0;j<palabra.length;j++){
				if (palabra[j]==entrada[j]){
					encontro=true;
				}
				else {
					encontro=false;
					break;
				}
			}
			
			if (encontro)
				return palabraEntry.getKey();
	 
		}
	
		return NO_ENCONTRO ;

	} 
	
	public static double[] getDoubleOfString(String palabra){
		
		if (palabras.containsKey(palabra))
			return palabras.get(palabra);
		
		return palabras.get(NO_ENCONTRO) ;

	}

	public static boolean exitoso(String valor) {
		if (valor.equals(NO_ENCONTRO) || valor.equals(ERROR_STRING))
			return false;
		return true;
	} 

	
}
